#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <algorithm>
using namespace std;

void help(vector<int>& nums,vector<vector<int>>&result,int& size,vector<int>&temp,vector<bool>&log){
    if(temp.size()==size){
        result.push_back(temp);
        return;
    }
    int t=INT_MAX;
    for(int i=0;i<size;i++){
        if(nums[i]==t)continue;
        if(log[i]==false){
            temp.push_back(nums[i]);
            log[i] = true;
        }else continue;
        help(nums,result,size,temp,log);
        t=temp.back();
        temp.pop_back();
        log[i] = false;
    }
}

vector<vector<int>> permute(vector<int>& nums) {
    vector<vector<int>>result;
    vector<int>temp;
    int size=nums.size();
    sort(nums.begin(),nums.end());
    vector<bool>log(size,false);
    help(nums,result,size,temp,log);
    return result;
}

int main(){
    vector<int>a={1,1,2};
    vector<vector<int>>result=permute(a);
    for(int i=0;i<result.size();i++){
        for(int j=0;j<3;j++){
            cout<<result[i][j]<<",";
        }
        cout<<"\n";
    }

    return 0;
}